package com.hps.txmsgdemo.bank2.service.impl;

import com.hps.txmsgdemo.bank2.dao.AccountInfoDao;
import com.hps.txmsgdemo.bank2.model.AccountChangeEvent;
import com.hps.txmsgdemo.bank2.service.AccountInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author heps
 * @date 2019/12/14 14:39
 */
@Slf4j
@Service
public class AccountInfoServiceImpl implements AccountInfoService {

    @Autowired
    private AccountInfoDao accountInfoDao;

    @Override
    public void addAccountInfoBalance(AccountChangeEvent accountChangeEvent) {
        if (accountInfoDao.isExistTx(accountChangeEvent.getTxNo()) > 0) {
            return;
        }
        accountInfoDao.updateAccountBalance(accountChangeEvent.getAccountNo(), accountChangeEvent.getAmount());
        accountInfoDao.addTx(accountChangeEvent.getTxNo());
    }
}
